<script lang="ts">
import { defineComponent, ref, onMounted, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { getVideo } from '../api/videodes'
import { viewCount, filters, vidotime } from '../hooks/filters'
import { getimage } from '../hooks/image'
import { storeToRefs } from 'pinia';
import { useCounterStore } from '../stores/home'
import { showToast } from 'vant'

export default defineComponent({
    setup() {
        const store = useCounterStore();

        const { idarr, likearr, collectlikearr, userInfoheard } = storeToRefs(store)
        // 作为 action 的 increment 可以直接解构
        const { increment, incrementfalse, unlikeFuns, likeFuns, collectFuns, uncollectFuns } = store;
        let router: any = useRouter();
        let route: any = useRoute();
        let myCollectjson: any = localStorage.getItem("collectlikearr");
        let myCollectArr: any = ref(JSON.parse(myCollectjson) || []);
        console.log(myCollectArr.value);
        myCollectArr.value = myCollectArr.value.reverse();
        console.dir(Array);
        let back = () => {
            router.back();
        }
        let tomyvideo = (videoid: any) => {
            router.push({
                path: '/myvideo',
                query: {
                    videoid
                }
            })
        };
        let videoDes: any = ref(null);
        let mycolllectArr: any = ref([]);
        let getVideoFun = (videoid: number) => {
            getVideo(videoid).then((data) => {
                console.log('视频详情=>', data)
                videoDes.value = data.data;
                mycolllectArr.value.push(videoDes.value);
                console.log('mycolllectArr=>', mycolllectArr.value)
            })
        }
        myCollectArr.value.forEach((item: any) => {
            console.log(item);
            getVideoFun(item)
        });
        //点击头像
        let click_user = (userid: number) => {
            router.push({
                path: '/userdetail',
                query: {
                    userid: userid,
                    active: 1
                }
            })
        };
        //点击视频
        let click_video = (videoid: any, video_library_id: any) => {
            router.push({
                path: '/videoDes',
                query: {
                    aid: videoid,
                    mid: video_library_id
                }
            })
        };
        // // 点击喜欢
        let likeFun = (id: any) => {
            likeFuns(id)

        }
        // 取消喜欢
        let unlikeFun = (id: any) => {
            unlikeFuns(id)
        }
        // 关注部分开始
        // 点击关注
        let attentiontaggtrue: any = (id: any) => {
            increment(id);
        }
        // 取消关注
        let attentiontaggfalse: any = (id: any) => {
            incrementfalse(id);
        };
        let collect: any = (id: any) => {
            collectFuns(id);
            collectlikearr.value = JSON.parse(window.localStorage.getItem('collectlikearr'));

        }
        // 取消关注
        let uncollect: any = (id: any,index:any) => {
            uncollectFuns(id);
            console.log(index)
            mycolllectArr.value.splice(index, 1);
            console.log('252525', myCollectArr.value);
            console.log(22222, collectlikearr.value)
        };

        const showShare = ref(false);
        const options = [
            { name: '微信', icon: 'wechat' },
            { name: '微博', icon: 'weibo' },
            { name: '复制链接', icon: 'link' },
            { name: '分享海报', icon: 'poster' },
            { name: '二维码', icon: 'qrcode' },
        ];
        const onSelect = (option: any) => {
            showToast(option.name);
            showShare.value = false;
        };
        return {
            back,
            myCollectArr,
            tomyvideo,
            vidotime,
            viewCount,
            getimage,
            getVideo,
            mycolllectArr,
            click_user,
            click_video,
            idarr,
            attentiontaggtrue,
            attentiontaggfalse,
            likeFun,
            unlikeFun,
            likearr,
            collectlikearr,
            collectFuns,
            uncollectFuns,
            options,
            showShare,
            onSelect,
            collect,
            uncollect
        }
    }
})
</script>
<template>
    <div style="min-height: 667px;background-color: #f7f7f7;">
        <div class="desbar">
            <span class="iconfont icon-xiangzuojiantou" @click="back"> </span>
            <h2>我的收藏</h2>
        </div>
        <div class="collectvideoList" v-if="mycolllectArr">
            <ul>
                <li @click.stop="click_video(item.id, item.video_library_id)" v-for="(item, index) in mycolllectArr"
                    :key="item.id">
                    <div class="content">
                        <!-- 发布用户信息 -->
                        <div class="user">
                            <div class="uer_left">
                                <div class="user_image" @click.stop="click_user(item.author.userinfo.id)">
                                    <!-- <img src="../assets/images/swiper1.webp" /> -->
                                    <img :src="getimage(item.author.userinfo.avatar)" />
                                    <div class="smallimage" v-if="item.author.userinfo.vip_flag == 1"
                                        style="background-color: #fff;">
                                        <img src="../assets/images/177会员、vip.png" />
                                    </div>
                                </div>
                                <div class="user_name">
                                    {{ item.author.userinfo.username }}
                                    <span class="iconfont icon-VIP1" v-if="item.author.userinfo.vip_flag == 1"
                                        style="color: #e73f29;font-size:14px"></span>
                                    <span v-if="item.team.length != 0">和其他<em>{{
                                        item.team.length }}</em>
                                        人</span>
                                </div>
                            </div>
                            <div class="user_right">
                                <div class="addfollow" @click.stop="attentiontaggtrue(item.author.userinfo.id)"
                                    v-if="!idarr.includes(item.author.userinfo.id)">+ 关注</div>
                                <div class="addfollow" @click.stop="attentiontaggfalse(item.author.userinfo.id)" v-else>已关注
                                </div>
                                <van-cell class="iconfont icon-Androidgengduo" />
                                <!-- <div class="logo"><span class="iconfont icon-gengduo"></span></div> -->
                                <!-- </van-cell> -->

                            </div>
                        </div>
                        <div class="word">{{ item.title }}</div>

                        <div class="video">
                            <img :src="getimage(item.cover)" />
                            <div class="play">

                            </div>
                            <!-- <img src="../assets/images/swiper1.webp" /> -->
                            <div class="mask">{{ viewCount(item.count.count_view) }}观看 |
                                {{ vidotime(item.duration) }}</div>
                        </div>
                        <div class="bottom">
                            <ul>
                                <!-- 收藏 -->
                                <li @click.stop="collect(item.id)" v-if="!collectlikearr.includes(item.id)"><span
                                        class="iconfont icon-31shoucang"></span>{{
                                            viewCount(item.count.count_collect) }}
                                </li>
                                <li @click.stop="uncollect(item.id,index)" v-else><span class="iconfont icon-wodeshoucang"
                                        style="color: yellow"></span>{{
                                            viewCount(item.count.count_collect + 1) }}
                                </li>
                                <!-- 评论 -->
                                <li><span class="iconfont icon-review"></span>{{
                                    viewCount(item.count.count_comment) }}
                                </li>
                                <!-- 喜欢 -->
                                <li @click.stop="likeFun(item.id)" v-if="!likearr.includes(item.id)"><span
                                        class="iconfont icon-dianzan"></span>{{
                                            viewCount(item.count.count_like) }}
                                </li>
                                <li @click.stop="unlikeFun(item.id)" v-else><span class="iconfont icon-dianzan_kuai "
                                        style="color: red;font-size: 19px;"></span>{{
                                            viewCount(item.count.count_like + 1) }}</li>
                            </ul>
                        </div>
                        <van-share-sheet v-model:show="showShare" title="立即分享给好友" :options="options" @select="onSelect" />
                    </div>
                </li>
            </ul>
            <p>没有更多了~</p>
        </div>
    </div>
</template>
<style lang="scss" scoped>
.desbar {
    display: flex;
    line-height: 44px;
    padding: 0 10px;
    position: sticky;
    z-index: 10;
    top: 0;
    background-color: #fff;

    span {
        font-size: 18px;
        font-weight: 600;
    }

    h2 {
        position: fixed;
        left: 50%;
        transform: translateX(-50%);
        font-size: 16px;

        // margin-left: 50px;
    }
}

::v-deep .van-cell {
    padding: 0;
    width: 20px;
}

::v-deep .van-popup {
    z-index: 666666;
    position: absolute !important;
    top: 36vh !important;
}

.collectvideoList {
    position: relative;

    &>ul {
        background-color: #f7f7f7;
        padding: 6px 15px;

        &>li {
            background-color: #fff;
            width: 100%;
            // height: 320px;
            border-radius: 10px;
            margin-bottom: 12px;
            border-top: 0.1px solid transparent;

            .content {
                .user {
                    padding: 0 12px;
                    margin-top: 12px;
                    display: flex;
                    justify-content: space-between;

                    .uer_left {
                        display: flex;

                        .user_image {
                            margin-right: 5px;
                            position: relative;

                            img {
                                border-radius: 50%;
                                width: 32px;
                                height: 32px;
                            }

                            .smallimage {
                                position: absolute;
                                top: 20px;
                                right: -3px;
                                width: 13px;
                                height: 13px;
                                display: flex;
                                align-items: center;
                                justify-content: center;
                                background-color: rgb(255, 255, 255);
                                border-radius: 50%;

                                img {
                                    width: 13px;
                                    height: 13px;
                                    border-radius: 50%;
                                }
                            }
                        }

                        .user_name {
                            font-size: 12px;
                            color: #484848;
                            line-height: 32px;

                            span {
                                color: #767676;

                                em {
                                    color: #1c1c1c;
                                    font-weight: 600;
                                    font-style: normal;
                                    margin-left: 4px;
                                }
                            }
                        }
                    }

                    .user_right {
                        display: flex;

                        .addfollow {
                            color: #eb4b3a;
                            font-size: 12px;
                            margin-right: 13px;
                            font-weight: 600;
                            line-height: 27px;
                        }

                        .logo {
                            span {
                                color: #8a8a8a;
                            }
                        }
                    }
                }

                .word {
                    padding: 0 12px;
                    font-size: 14px;
                    color: #282828;
                    font-weight: 600;
                    line-height: 31px;
                }

                .video {
                    position: relative;
                    height: 203px;
                    display: flex;
                    align-items: center;

                    img {
                        width: 100%;
                        height: 199px;
                        display: flex;
                    }

                    .play {
                        position: absolute;
                        top: 50%;
                        left: 50%;
                        transform: translate(0%, -50%);
                        color: #fff;
                        font-size: 12px;
                        width: 0;
                        height: 0;
                        border: 10px solid transparent;
                        border-left: 15px solid #fff;
                    }

                    .mask {
                        position: absolute;
                        bottom: 0;
                        right: 0;
                        color: #fff;
                        font-size: 12px;
                        margin-right: 12px;
                        line-height: 30px;
                    }
                }

                .bottom {
                    &>ul {
                        display: flex;
                        align-items: center;

                        &>li {
                            width: 33.33%;
                            text-align: center;
                            line-height: 44px;
                            font-size: 12px;
                            display: flex;
                            align-items: center;
                            justify-content: center;

                            span {
                                margin-right: 7px;
                                font-size: 20px;
                                color: #6a6869;
                            }
                        }
                    }
                }
            }
        }
    }

    &>p {
        text-align: center;
        line-height: 50px;
        color: #8a8a8a;
        font-size: 14px;
        // background-color: #f7f7f7;
    }
}
</style>